import 'package:eshi/app/shi/data/HistoryMarks.dart';
import 'package:eshi/app/shi/data/HistoryPoint.dart';
import 'package:eshi/app/shi/data/parse/IndentParser.dart';
import 'package:eshi/app/shi/data/parse/TxtPointParser.dart';
class TxtTabPointParser extends TxtPointParser{
  TxtTabPointParser(super.history);
  
    onPointCreate(HistoryPoint point){
      point.enable = false;
      switch(point.name){
        case "序":
          history.coverPage = parseDataToText(point.data);
          return null;
        case "引用":
          var keys = HistoryMarks.values.map((v){return v.name;});
          for(var key in keys){
            if(point.data.containsKey(key)){
              var text = parseDataToText(point.data[key]);
              var marks = text.substring(key.length).trim().split(RegExp('[,，\n]+'));
              history.addMark(key,marks);
            }
          }
          return null;
        default:
          point.parseName();
      }
      point.enable =true;
    }
    
   String parseDataToText(pData) {
      if(pData is List){
         var rt=[];
         for (var v in pData) {
            rt.add(parseDataToText(v));
         }
         return rt.join("\n");
      }
      
      if(!IndentParser.isNode(pData)){
          var rt = [];
          pData.forEach((k,v){
              rt.add(IndentParser.decode(v));
          });
          return rt.join("\n");
      }
      
      return IndentParser.decode(pData);
   }
}